/*
 * 
 * Raj Akula	
 * Inventory Look Up Android Application
 * CSC 594
 * 
 * DatabaseHelper
 * Creates Database and initlizes it..  
 * 
 */



package nku.csc364.databasehelper;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;

public class DatabaseHelper extends SQLiteOpenHelper {
	private static final String DATABASE_NAME="db";
	static final String TITLE="title";
	static final String VALUE="value";
	
	public DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, 1);
	}
	
	@Override
	public void onCreate(SQLiteDatabase db) 
	{
		db.execSQL("CREATE TABLE categorys (_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, desc TEXT);");
		db.execSQL("CREATE TABLE products (_id INTEGER PRIMARY KEY AUTOINCREMENT, category TEXT, name TEXT, desc TEXT, pict INTEGER);");
		db.execSQL("CREATE TABLE items (_id INTEGER PRIMARY KEY AUTOINCREMENT, product TEXT, name TEXT, status TEXT, listprice REAL, unitcost REAL, supplier TEXT, pict INTEGER);");
		db.execSQL("CREATE TABLE suppliers (_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, status TEXT, addr1 TEXT, addr2 TEXT, city TEXT, state TEXT, zip TEXT, phone TEXT);");
		db.execSQL("CREATE TABLE inventory (_id INTEGER PRIMARY KEY AUTOINCREMENT, item TEXT, qty INTEGER);");
		
		insertCategories(db);
		insertProducts(db);
		insertItems(db);
		insertSuppliers(db);
		
	}
	
	public void insertCategories(SQLiteDatabase db){
		ContentValues cv = new ContentValues();
		
		cv.put("name", "Desktop");
		cv.put("desc", "A PC that is not easy to move and gets work done.");
		db.insert("categorys", "category", cv);
		
		cv.put("name", "Laptop");
		cv.put("desc", "A PC that is easy to move and gets work done.");
		db.insert("categorys", "category", cv);
		
		cv.put("name", "Tablet");
		cv.put("desc", "A PC that is easy to move and gets no work done.");
		db.insert("categorys", "category", cv);
		
		cv.put("name", "Phone");
		cv.put("desc", "A PC in your pocket, that makes phone calls.");
		db.insert("categorys", "category", cv);
	}

	private void insertItems(SQLiteDatabase db) {
			ContentValues cv = new ContentValues();
			
			cv.put("category", "Desktop");
			cv.put("name", "High-End Desktop");
			cv.put("desc", "Heavy Configuration Desktop");
			cv.put("pic", 0);
		//	db.insert(table, nullColumnHack, values)
			
			cv.put("category", "Desktop");
			cv.put("name", "High-End Desktop");
			cv.put("desc", "Heavy Configuration Desktop");
			cv.put("pic", 0);
		
	}
	
	private void insertProducts(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		
	}

	private void insertSuppliers(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
	{
		android.util.Log.w("Constants", "Upgrading database, which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS constants");
		onCreate(db);
	}
	
}